import orm
import time


# 显示账单（显示总支出金额，总收入金额，结余金
def show_data():
    revenue = 0
    expenditure = 0
    path = r'user.json'
    data = orm.read_data(path)
    for sos in data:
        money = float(sos['金额'])
        print(money)
        if money > 0:
            revenue += money
        if money < 0:
            expenditure -= money
    print(f'总收入金额为：{revenue}')
    print(f'总支出金额为：{expenditure}')
    print(f'余额为：{revenue-expenditure}')


def write_data():
    path = r'user.json'
    name = input('请输入项目:')
    user = input('请输入类型:')
    money = float(input('请输入金额:'))
    time1=time.strftime('%Y-%m-%d %H:%M:%S')
    new_user = {'time': time1,'项目': name,'类型': user,'金额': money}
    user_list = orm.read_data(path)
    user_list.append(new_user)
    orm.write_data(user_list, path)




